package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Comment;
import com.cskaoyan.bean.OrderGoods;
import com.cskaoyan.bean.bo.CommentBo;
import com.cskaoyan.mapper.CommentMapper;
import com.cskaoyan.service.wxService.WxOrderService;
import com.cskaoyan.service.CommentService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("wx/order")
public class WxOrderController {

    @Autowired
    WxOrderService wxOrderService;
    @Autowired
    CommentService commentService;
    @Autowired
    CommentMapper commentMapper;

    @GetMapping("list")
    public BaseRespVo orderList(Integer showType,Integer page,Integer size) {
        Map<String, Object> map = wxOrderService.orderList(showType, page, size);

        return BaseRespVo.ok(map);
    }
    @GetMapping("goods")
    public BaseRespVo ordergoods(Integer orderId, Integer goodsId) {

        OrderGoods orderGoods = wxOrderService.ordergoods(orderId, goodsId);

        return BaseRespVo.ok(orderGoods);
    }

    @GetMapping("detail")
    public BaseRespVo orderDetail(Integer orderId) {

        Map<String, Object> map = wxOrderService.orderDetail(orderId);

        return BaseRespVo.ok(map);
    }

    @PostMapping("delete")
    public BaseRespVo deleteWxOrder(@RequestBody Map<String, Integer> map) {

        Integer orderId = map.get("orderId");
        wxOrderService.deleteWxOrder(orderId);
        return BaseRespVo.ok();
    }

    @RequestMapping("submit")
    public BaseRespVo submitWxOrder(@RequestBody Map<String,Object> map){
        Integer addressId = (Integer) map.get("addressId");
        Integer couponId = (Integer) map.get("couponId");
        Integer cartId = (Integer) map.get("cartId");
        Integer orderId = wxOrderService.OrderSubmit(addressId, couponId, cartId);
        Map<String,Object> singleKeyMap = new HashMap<>();
        singleKeyMap.put("orderId",orderId);
        return BaseRespVo.ok(singleKeyMap);
    }
    @PostMapping("confirm")
    public BaseRespVo confirmWxOrder(@RequestBody Map<String,Integer> map){

        Integer orderId = map.get("orderId");
        wxOrderService.confirmWxOrder(orderId);
        return BaseRespVo.ok();
    }
    @PostMapping("refund")
    public BaseRespVo refundWxOrder(@RequestBody Map<String,Integer> map){

        Integer orderId = map.get("orderId");
        wxOrderService.refundWxOrder(orderId);
        return BaseRespVo.ok();
    }
    @PostMapping("cancel")
    public BaseRespVo cancelWxOrder(@RequestBody Map<String,Integer> map){

        Integer orderId = map.get("orderId");
        wxOrderService.cancelWxOrder(orderId);
        return BaseRespVo.ok();
    }


    @PostMapping("comment")
    public BaseRespVo wxOrderComment(@RequestBody Map<String,Object> map){
        wxOrderService.wxOrderComment(map);
        return BaseRespVo.ok();
    }

}
